#install torch in a venv python
Explore tagged Tumblr posts
Text
How to Install PyTorch
PyTorch is a framework for the Python programming language, designed for machine learning. It includes a set of tools for working with models, commonly used in natural language processing, computer vision, and other similar fields. You can install it on your server manually using this guide.
PyTorch Installation on Linux¶
This instruction is suitable for the following operating systems: Ubuntu 22.04, and verified for Python versions: Python 3.10.
Install Python:sudo apt install python3.10 In Ubuntu 22.04, this version is installed by default, so we do not recommend installing a newer version.
Create a virtual environment for Python:python3 -m venv venv
Activate the virtual environment:source venv/bin/activate After successful activation, the prompt will include the name of the virtual environment in parentheses:(venv) user@49069:~$ NoteYou can create as many virtual environments as you like and install different libraries (including simultaneously, but sometimes this may cause conflicts).
Install PyTorch libraries in the virtual environment:pip3 install torch torchvision torchaudio
Verify PyTorch installation:To do this, run a Python console command python and then run the following program:import torch x = torch.rand(5, 3) print(x) If the installation is successful, you will receive the following output:(venv) user@49069:~$ python Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>> x = torch.rand(5, 3) >>> print(x) tensor([[0.80, 0.04, 0.6], [0.32, 0.59, 0.7], [0.8, 0.70, 0.25], [0.40, 0.9, 0.9], [0.8, 0.15, 0.5]])
Verify if PyTorch libraries use CUDA:To do this, run the following program in a Python console:import torch torch.cuda.is_available() If PyTorch can work in GPU mode, the output will be: >>> import torch >>> torch.cuda.is_available() True
#install torch in a venv python#torchvision module insall#install pytorch#how to download torch on linux#can't install torch on linux#how to verify pytorch installed properly
1 note
·
View note
Text
Stable Diffusion Service Deployment —— SD WebUI on CentOS7
框架依赖安装
1. sudo yum update 并重启
更新ssl,为了安装Python3.10.6
whereis openssl | xargs rm -frv
yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN -y
<!-- 进入perl命令行内执行 -->
perl -MCPAN -e shellinstall IPC/Cmd.pm
<!-- 下载SSL version>=1.1.1k 2021-3-25 -->
wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz
tar -zxvf openssl-1.1.1q.tar.gz
cd openssl-1.1.1q
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib
make && make install
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v
ln -s /usr/local/openssl/bin/openssl /usr/bin/opensslopenssl
安装Python3.10.6,为了能运行特定版本torch/CUDA
whereis python3 | xargs rm -frv
whereis pip3 | xargs rm -frv
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make python3-devel libevent-devel python-gevent libffi-devel
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz
tar -zxvf Python-3.10.6.tgz
cd Python-3.10.6
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
make && make install
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
python3 --version
4. 安装Git(>=1.8.5),为了能执行大文件下载
yum install epel-release
yum remove git
yum install https://repo.ius.io/ius-release-el7.rpm
yum search git2 //下行的具体版本会变,可通过search确定
yum install git236
yum install git-lfs
安装显卡驱动
yum install pciutils
wget https://us.download.nvidia.com/tesla/460.106.00/NVIDIA-Linux-x86_64-460.106.00.run
yum install -y kernel-devel-$(uname -r) kernel-headers-$(uname -r)
sh NVIDIA-Linux-x86_64-460.106.00.run
nvidia-smi
框架安装
wget https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh
<!-- 修改webui.sh脚本,将默认路径从 /home/$(whoami) 改为自定义路径 -->
<!-- 改个清华镜像加速-->
/......../stable-diffusion-webui/venv/bin/python3 -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple sh webui.sh
<!-- 如果安装出现问题,可以先自行git clone 到local,再如下从本地安装 -->
/......../stable-diffusion-webui/venv/bin/python3 -m pip install git+file:///data/sd/GFPGAN
/......../stable-diffusion-webui/venv/bin/python3 -m pip install git+file:///data/sd/CLIP
/......../stable-diffusion-webui/venv/bin/python3 -m pip install git+file:///data/sd/open_clip
<!-- 如果安装出现zlib版本问题 -->
从 https://github.com/DiffusionHub/DiffusionHub 下载zlib-1.2.9
tar -xvf ~/Downloads/zlib-1.2.9.tar.gz
cd zlib-1.2.9
sudo -s
./configure; make; make install
make install完会生成zlib-1.2.9,将/lib下的libz.so和libz.so.1 软链接到这个zlib-1.2.9,如 ln -s -f /lib/libz.so.1.2.9/lib libz.so.1
模型安装
Stable Diffusion模型
2.0以下模型可以直接把ckpt模型文件放在WebUI目录内models/Stable-diffusion 路径下
2.0及以上模型需要额外的参数描述文件yaml,可以从 https://github.com/Stability-AI/stablediffusion/tree/main/configs/stable-diffusion 下载相应yaml,分辨率为512x512的用v2-inference.yaml,768x768的用v2-inference-v.yaml* NovelAI leaked model
服务发布
WebUI: sh webui.sh --listen
API: sh webui.sh --nowebui --listen
指定使用的显卡,例如
0 notes